<style>
    .layui-table-cell .layui-table-sort {
        display: none;
    }

    .addProductionPlanForm-title .title, .examineProductionPlanForm-title .title {
        display: inline-block;
        margin: 20px;
        font-size: 16px;
        font-weight: bold;
        color: #333333;
        line-height: 19px;
        position: relative;
        padding: 6px 0 19px 0;
    }

    .addProductionPlanForm-title .title:after, .examineProductionPlanForm-title .title:after {
        content: '';
        display: block;
        position: absolute;
        left: 0;
        bottom: 0;
        width: calc(100% + 6px);
        height: 3px;
        background: #0A8B0A;
    }
</style>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label">提货订单编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="orderNo" id="orderNo" class="layui-input"
                                               type="text"
                                               placeholder="请输入提货订单编号" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">客户名称：</label>
                                    <div class="layui-input-inline">
                                        <input name="customerName" id="customerName" class="layui-input"
                                               type="text"
                                               placeholder="请输入客户名称" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">采购组织：</label>
                                    <div class="layui-input-inline">
                                        <input name="purchaseCode" id="purchaseCode" class="layui-input"
                                               type="text"
                                               placeholder="请输入采购组织" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">物料编码：</label>
                                    <div class="layui-input-inline">
                                        <input name="skuCode" id="skuCode" class="layui-input"
                                               type="text"
                                               placeholder="请输入物料编码" autocomplete="off"/>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit layui-form-keyDownSearch="true">查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>
                                        重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="lay-btn-rows">
                        <div class="lay-btn-box">
                            <div class="lay-btn-lt">
                                <button id="productOrderDetailAdd" type="button" class="layui-btn icon-btn color-reseda">
                                    添加提货明细
                                </button>
                                <button id="batchInsert" type="button" class="layui-btn icon-btn color-reseda">
                                    批量导入
                                </button>
                                <button id="downTemplate" type="button" class="layui-btn icon-btn color-reseda">
                                    下载模板
                                </button>
                            </div>
                            <div class="lay-btn-rt"></div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="proDeliveryOrderDetailTableInfo" lay-filter="proDeliveryOrderDetailTableInfo"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="proQualityTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</a>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'laydate', 'admin', 'laytpl', 'tableTreeDj', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var table = layui.table;
        var form = layui.form;
        var config = layui.config;
        var admin = layui.admin;

        laydate.render({
            elem: '#givenStartTimed'
            , format: "yyyy-MM-dd"
            , range: "至"
        });

        // 渲染表格
        var insTb = table.render({
            elem: '#proDeliveryOrderDetailTableInfo',
            url: config.base + 'production/delivery/admin/orderDetailInfo/list',
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号', align: 'center'}
                , {field: 'orderNo', title: '提货订单编号', align: 'center', width: 150}
                , {field: 'skuCode', title: '物料编码', align: 'center', width: 130}
                , {field: 'skuName', title: '物料名称', align: 'center', width: 130}
                , {field: 'productionLine', title: '生产线', align: 'center'}
                , {field: 'customerName', title: '所属客户', align: 'center'}
                , {field: 'purchaseCode', title: '采购组织', align: 'center'}
                , {field: 'deliveryNum', title: '提货数', align: 'center'}
                , {field: 'sendNum', title: '发货数', align: 'center'}
                , {field: 'unitName', title: '单位', align: 'center'}
                , {field: 'deliveryTime', title: '提货时间', align: 'center', width: 120}
                // , {field: 'deliveryNatureName', title: '添加性质', align: 'center'}
                , {field: 'statusName', title: '状态', align: 'center'}
                , {field: 'remark', title: '组件描述', align: 'center'}
                , {align: 'center', toolbar: '#proQualityTableBar', title: '操作', width: 150}
            ]]
        });

        //渲染下拉
        form.render('select');

        //下载模板的点击事件
        $('#downTemplate').click(function () {
            window.location.href = config.base + "production/delivery/admin/orderDetailInfo/template";
        });

        //batchInsert
        $('#batchInsert').click(function () {
            batchInsert();
        });

        function batchInsert() {
            admin.formOpen({
                type: 1,
                area: ['62%', '54%'],
                offset: ['20%','28%'],
                style: 'font-size: 20px;',
                title: "明细导入",
                path: "components/product/delivery/batchInsert.html",
                done: function () {
                    insTb.reload({}, 'data');
                }
            });
        }


        // 工具条点击事件
        table.on('tool(proDeliveryOrderDetailTableInfo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                productOrderDetailAdd(data);
            } else if (obj.event === 'detail') { //详情
                showDetailModel(data);
            }
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            data.field.givenStartTimed = $("#givenStartTimed").val();
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', data => {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        // 添加按钮点击事件
        $('#productOrderDetailAdd').click(function () {
            productOrderDetailAdd();
        });
        
        function showDetailModel(data) {
            admin.putTempData("productDetailOrderKKData", data);
            admin.formOpen({
                type: 1,
                area: ['62%;', '90%'],
                style: 'font-size: 20px;',
                title: "详情",
                path: "components/product/delivery/orderDetailDetailInfo.html",
                done: function () {
                    insTb.reload({where: data.field, page: {curr: 1}}, 'data');
                }
            });
        }
        
        function productOrderDetailAdd(data) {
            let title;
            let path;
            if (data) {
                title = "修改提货订单";
                admin.putTempData("orderDetailInfoUpdate",data)
                path = "components/product/delivery/orderDetailUpdate.html"
            } else {
                title = "添加提货订单";
                path = "components/product/delivery/orderDetailAdd.html"
            }

            admin.formOpen({
                type: 1,
                area: ['62%;', '90%'],
                style: 'font-size: 20px;',
                title: title,
                path: path,
                done: function () {
                    // table.reload(insTb, {});
                    insTb.reload({where: data.field, page: {curr: 1}}, 'data');
                }
            });
        }
    });
</script>